home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programmer Power Tools
/
Programmer Power Tools.iso
/
microcrn
/
issue_37.arc
/
LASTPG37.FIG
< prev
next >
Wrap
Text File
|
1987-08-05
|
2KB
|
67 lines
/* listing 1 ``Lucid Lucy'' */
DOMAINS
integerlist = integer*
stringlist = string*
DATABASE
input(stringlist,integer)
output(integer,string)
PREDICATES
start
main
check_table(stringlist,stringlist)
compare(string,string)
process(string)
string_to_list(string, stringlist)
CLAUSES
start:- /* Set up continuation */
main. /* By using 2 predicates, */
start:- /* start and main, & fail */
start. /* we can clear the stack, */
/* and conserve memory. */
main:-
readln(Sent), /* Read input string. */
string_to_list(Sent,S2), /* Convert string to list. */
input(L,ActNo), /* Get an input record. */
check_table(S2,L), /* Compare input list */
/* with input record. */
output(ActNo,Action), /* If match, get output. */
process(Action), /* Act. */
!,fail. /* Continue by forcing
/* backtracking with fail. */
main.
check_table([H|T],[H2|T2]):- /* Recursively compare heads. */
compare(H,H2),
check_table(T,T2).
check_table([],[]).
compare(H,H2):- /* Do the actual comparison */
H = H2. /* here. */
compare(H,H2):- /* If the record allows */
H2 = "_". /* wildcards, succeed. */
process("greeting"):- /* Execute an instruction. */
write("Hello there."), /* Expand Lucy by adding */
nl. /* predicates here. */
process("greeting2"):-
write("Hello, how are you?."),
nl.
process("exit"):-
write("Goodbye."),
exit.
process(_).
string_to_list(S,[H|T]):- /* Convert an input string */
fronttoken(S,H,S1),!, /* to a string list. */
string_to_list(S1,T).
string_to_list(_,[]).
GOAL
consult("input.dba"), /* Load knowledge bases */
consult("output.dba"),
start. /* and begin. */